﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Xml.Serialization;
using System.Xml;

namespace LfmApi
{
    [ServiceContract]
    [XmlSerializerFormat]
    public interface IApi
    {
        //TODO: album_addTags

        [OperationContract(Name = "album_getInfo(artist, album)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.getinfo&artist={artist}&album={album}")]
        album album_getInfo(string apikey, string artist, string album);

        [OperationContract(Name = "album_getInfo(mbid)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.getinfo&mbid={mbid}")]
        album album_getInfo(string apikey, string mbid);

        //TODO: album_getTags 
        //TODO: album_removeTag 

        [OperationContract(Name = "album_search(album)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.search&album={album}")]
        results album_search(string apikey, string album);

        [OperationContract(Name = "album_search(album, limit)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.search&album={album}&limit={limit}")]
        results album_search(string apikey, string album, int limit);

        [OperationContract(Name = "album_search(album, page)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.search&album={album}&page={page}")]
        results album_search(string apikey, string album, string page);

        [OperationContract(Name = "album_search(album, limit, page)")]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "?raw=true&api_key={apikey}&method=album.search&album={album}&limit={limit}&page={page}")]
        results album_search(string apikey, string album, int limit, string page);


        //TODO: artist_addTags 
        //TODO: artist_getEvents 
        //TODO: artist_getImages 
        //TODO: artist_getInfo 
        //TODO: artist_getShouts 
        //TODO: artist_getSimilar 
        //TODO: artist_getTags 
        //TODO: artist_getTopAlbums 
        //TODO: artist_getTopFans 
        //TODO: artist_getTopTags 
        //TODO: artist_getTopTracks 
        //TODO: artist_removeTag 
        //TODO: artist_search 
        //TODO: artist_share 
        //TODO: artist_shout 

        //TODO: auth_getMobileSession 
        //TODO: auth_getSession 
        //TODO: auth_getToken 
        //TODO: auth_getWebSession 

        //TODO: event_attend 
        //TODO: event_getAttendees 
        //TODO: event_getInfo 
        //TODO: event_getShouts 
        //TODO: event_share 
        //TODO: event_shout 

        //TODO: geo_getEvents 
        //TODO: geo_getTopArtists 
        //TODO: geo_getTopTracks 

        //TODO: group_getMembers 
        //TODO: group_getWeeklyAlbumChart 
        //TODO: group_getWeeklyArtistChart 
        //TODO: group_getWeeklyChartList 
        //TODO: group_getWeeklyTrackChart 

        //TODO: library_addAlbum 
        //TODO: library_addArtist 
        //TODO: library_addTrack 
        //TODO: library_getAlbums 
        //TODO: library_getArtists 
        //TODO: library_getTracks 

        //TODO: playlist_addTrack 
        //TODO: playlist_create 
        //TODO: playlist_fetch 

        //TODO: radio_getPlaylist 
        //TODO: radio_tune 

        //TODO: tag_getSimilar 
        //TODO: tag_getTopAlbums 
        //TODO: tag_getTopArtists 
        //TODO: tag_getTopTags 
        //TODO: tag_getTopTracks 
        //TODO: tag_getWeeklyArtistChart 
        //TODO: tag_getWeeklyChartList 
        //TODO: tag_search 

        //TODO: tasteometer_compare 

        //TODO: track_addTags 
        //TODO: track_ban 
        //TODO: track_getInfo 
        //TODO: track_getSimilar 
        //TODO: track_getTags 
        //TODO: track_getTopFans 
        //TODO: track_getTopTags 
        //TODO: track_love 
        //TODO: track_removeTag 
        //TODO: track_search 
        //TODO: track_share 

        //TODO: user_getEvents 
        //TODO: user_getFriends 
        //TODO: user_getInfo 
        //TODO: user_getLovedTracks 
        //TODO: user_getNeighbours 
        //TODO: user_getPastEvents 
        //TODO: user_getPlaylists 
        //TODO: user_getRecentTracks 
        //TODO: user_getRecommendedArtists 
        //TODO: user_getRecommendedEvents 
        //TODO: user_getShouts 
        //TODO: user_getTopAlbums 
        //TODO: user_getTopArtists 
        //TODO: user_getTopTags 
        //TODO: user_getTopTracks 
        //TODO: user_getWeeklyAlbumChart 
        //TODO: user_getWeeklyArtistChart 
        //TODO: user_getWeeklyChartList 
        //TODO: user_getWeeklyTrackChart 
        //TODO: user_shout 

        //TODO: venue_getEvents 
        //TODO: venue_getPastEvents 
        //TODO: venue_search 

    }

    [XmlRoot("album")]
    public class album
    {
        [XmlElement]
        public string name { get; set; }

        [XmlElement]
        public string artist { get; set; }

        [XmlElement]
        public string id { get; set; }

        [XmlElement]
        public string mbid { get; set; }

        [XmlElement]
        public string url { get; set; }

        [XmlElement]
        public string releasedate { get; set; }

        [XmlElement("image")]
        public type_image[] images { get; set; }

        [XmlType]
        public class type_image
        {
            [XmlAttribute]
            public string size { get; set; }

            [XmlText]
            public string url { get; set; }
        }

        [XmlElement]
        public string listeners { get; set; }

        [XmlElement]
        public string playcount { get; set; }

        [XmlArray("toptags")]
        [XmlArrayItem("tag")]
        public type_tag[] toptags { get; set; }

        [XmlType]
        public class type_tag
        {
            [XmlElement]
            public string name { get; set; }

            [XmlElement]
            public string url { get; set; }
        }

        [XmlElement]
        public type_wiki wiki { get; set; }

        [XmlType]
        public class type_wiki
        {
            [XmlElement]
            public string summary { get; set; }

            [XmlElement]
            public string content { get; set; }
        }

        [XmlElement]
        public string streamable { get; set; }
    }

    [XmlRoot("results")]
    public class results
    {
        [XmlAttribute]
        public string @for { get; set; }

        [XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
        public type_query Query { get; set; }
        
        [XmlType]
        public class type_query
        {
            [XmlAttribute]
            public string role { get; set; }
            [XmlAttribute]
            public string searchTerms { get; set; }
            [XmlAttribute]
            public string startPage { get; set; }

        }

        [XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
        public int totalResults { get; set; }

        [XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
        public int startIndex { get; set; }

        [XmlElement(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
        public int itemsPerPage { get; set; }

        [XmlArray("albummatches")]
        [XmlArrayItem("album")]
        public album[] albummatches { get; set; }
    }
}
